package com.whnk.web.controller.pm;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.whnk.common.annotation.Log;
import com.whnk.common.enums.BusinessType;
import com.whnk.pm.domain.IdleResult;
import com.whnk.pm.service.IIdleResultService;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.common.base.AjaxResult;

/**
 * 人员缺勤 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-08-29
 */
@Controller
@RequestMapping("/pm/idleResult")
public class IdleResultController extends BaseController
{
    private String prefix = "pm/idleResult";
	
	@Autowired
	private IIdleResultService idleResultService;
	
	@RequiresPermissions("pm:idleResult:view")
	@GetMapping()
	public String idleResult()
	{
	    return prefix + "/idleResult";
	}
	
	/**
	 * 查询人员缺勤列表
	 */
	@RequiresPermissions("pm:idleResult:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(IdleResult idleResult)
	{
		startPage();
        List<IdleResult> list = idleResultService.selectIdleResultList(idleResult);
		return getDataTable(list);
	}
	
	/**
	 * 新增人员缺勤
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存人员缺勤
	 */
	@RequiresPermissions("pm:idleResult:add")
	@Log(title = "人员缺勤", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(IdleResult idleResult)
	{		
		return toAjax(idleResultService.insertIdleResult(idleResult));
	}

	/**
	 * 修改人员缺勤
	 */
	@GetMapping("/edit/{idleId}")
	public String edit(@PathVariable("idleId") Integer idleId, ModelMap mmap)
	{
		IdleResult idleResult = idleResultService.selectIdleResultById(idleId);
		mmap.put("idleResult", idleResult);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存人员缺勤
	 */
	@RequiresPermissions("pm:idleResult:edit")
	@Log(title = "人员缺勤", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(IdleResult idleResult)
	{		
		return toAjax(idleResultService.updateIdleResult(idleResult));
	}
	
	/**
	 * 删除人员缺勤
	 */
	@RequiresPermissions("pm:idleResult:remove")
	@Log(title = "人员缺勤", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(idleResultService.deleteIdleResultByIds(ids));
	}
}
